package edu.sctu.zhoumengxue.day201506.day20150628.test;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

/**获取网页上的数据
 * Created by user12 on 2015/6/28.
 */
public class URLPost{

    public int count;
    public String string = "";
    public byte[] bytes = new byte[1024];

    public  String getURL(String path){

         int count;
         String string = "";
         byte[] bytes = new byte[1024];

        try {
            URL url = new URL(path);
            try {

                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                connection.connect();

                InputStream in = connection.getInputStream();
                while ((count = in.read(bytes))!=-1){
                    string =string + new String(bytes,0,count,"Utf-8");
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        return string;
    }

}
